---
title: Debugging Issues
layout: page
pageOrder: 8
section: 'Mock Server'
subsection: true
sitemap:
  priority: 0.7
  changefreq: 'monthly'
  lastmod: 2018-11-16T16:00:00+01:00
---

<p>MockServer supports the following features to simplify debugging</p>

<ul>
    <li>
        <p>Retrieve the following items:</p>
        <ul>
            <li><strong><a href="#retrieving_recorded_requests">recorded requests</a></strong></li>
            <li><strong><a href="#retrieving_recorded_requests">active expectations</a></strong></li>
            <li><strong><a href="#retrieving_recorded_requests">recorded expectations</a></strong></li>
            <li><strong><a href="#retrieving_recorded_requests">logs</a></strong></li>
        </ul>
    </li>
    <li>Configurable <a href="#logging-levels">log level</a></li>
    <li>Clear and simple log messages for all actions</li>
    <li>JSON Schema validation of all requests to the REST API, with clear failure messages</li>
    <li>Clear failure messages when verifying requests (that support "show difference" in IntelliJ)</li>
</ul>

<a name="retrieving_recorded_requests" class="anchor" href="#retrieving_recorded_requests">&nbsp;</a>

<h2>Retrieving Recorded Requests</h2>

<p>All requests the MockServer or the proxy receives are recorded.</p>

<p>It is possible to retrieve the recorded request, as show below in the code examples.</p>

<p>Requests are returned in the order they are received, and which requests are returned can be filter using a <a href="/mock_server/getting_started.html#request_matchers">request matcher</a>.</p>

<button id="button_recorded_reqs" class="accordion title"><strong>Retrieving Recorded Requests Code Examples</strong></button>
<div class="panel title">
    <button id="button_retrieve_all_recorded_reqs" class="accordion">retrieve all recorded requests</button>
    <div class="panel">
        <button class="accordion inner">Java</button>
        <div class="panel">
            <pre class="prettyprint lang-java code"><code class="code">HttpRequest[] recordedRequests = new MockServerClient("localhost", 1080)
    .retrieveRecordedRequests(
        request()
    );</code></pre>
        </div>
        <button class="accordion inner">JavaScript</button>
        <div class="panel">
            <pre class="prettyprint lang-javascript code"><code class="code">var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
    .retrieveRecordedRequests({})
    .then(
        function (recordedRequests) {
            console.log(JSON.stringify(recordedRequests));
        },
        function (error) {
            console.log(error);
        }
    );</code></pre>
        </div>
        <button class="accordion inner">REST API</button>
        <div class="panel">
            <pre class="prettyprint code"><code class="code">curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=REQUESTS"</code></pre>
        </div>
    </div>
    <button id="button_retrieve_recorded_reqs_using_request_matcher" class="accordion">retrieve recorded requests using request matcher</button>
    <div class="panel">
        <button class="accordion inner">Java</button>
        <div class="panel">
            <pre class="prettyprint lang-java code"><code class="code">HttpRequest[] recordedRequests = new MockServerClient("localhost", 1080)
    .retrieveRecordedRequests(
        request()
            .withPath("/some/path")
            .withMethod("POST")
    );</code></pre>
        </div>
        <button class="accordion inner">JavaScript</button>
        <div class="panel">
            <pre class="prettyprint lang-javascript code"><code class="code">var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080).retrieveRecordedRequests({
    "path": "/some/path",
    "method": "POST"
}).then(
    function (recordedRequests) {
        console.log(JSON.stringify(recordedRequests));
    },
    function (error) {
        console.log(error);
    }
);</code></pre>
        </div>
        <button class="accordion inner">REST API</button>
        <div class="panel">
            <pre class="prettyprint code"><code class="code">curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=REQUESTS" -d '{
    "path": "/some/path",
    "method": "POST"
}'</code></pre>
        </div>
    </div>
    <button id="button_retrieve_recorded_reqs_as_java" class="accordion">retrieve recorded requests as java</button>
    <div class="panel">
        <button class="accordion inner">Java</button>
        <div class="panel">
            <pre class="prettyprint lang-java code"><code class="code">String recordedRequests = new MockServerClient("localhost", 1080)
    .retrieveRecordedRequests(
        request()
            .withPath("/some/path")
            .withMethod("POST"),
        Format.JAVA
    );</code></pre>
        </div>
        <button class="accordion inner">REST API</button>
        <div class="panel">
            <pre class="prettyprint code"><code class="code">curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=REQUESTS&format=JAVA" -d '{
    "path": "/some/path"
}'</code></pre>
        </div>
    </div>
    <button id="button_retrieve_recorded_reqs_as_json" class="accordion">retrieve recorded requests as json</button>
    <div class="panel">
        <button class="accordion inner">Java</button>
        <div class="panel">
            <pre class="prettyprint lang-java code"><code class="code">String recordedRequests = new MockServerClient("localhost", 1080)
    .retrieveRecordedRequests(
        request()
            .withPath("/some/path")
            .withMethod("POST"),
        Format.JSON
    );</code></pre>
        </div>
        <button class="accordion inner">JavaScript</button>
        <div class="panel">
            <pre class="prettyprint lang-javascript code"><code class="code">var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080).retrieveRecordedRequests({
    "path": "/some/path",
    "method": "POST"
}).then(
    function (recordedRequests) {
        console.log(JSON.stringify(recordedRequests));
    },
    function (error) {
        console.log(error);
    }
);</code></pre>
        </div>
        <button class="accordion inner">REST API</button>
        <div class="panel">
            <pre class="prettyprint code"><code class="code">curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=REQUESTS&format=JSON" -d '{
    "path": "/some/path"
}'</code></pre>
        </div>
    </div>
</div>

<a name="retrieving_active_expectations" class="anchor" href="#retrieving_active_expectations">&nbsp;</a>

<h2>Retrieving Active Expectations</h2>

<p>It is possible to retrieve the active expectations, as show below in the code examples.</p>

<p>Expectations are returned in the order they have been added, and which expectations are returned can be filter using a <a href="/mock_server/getting_started.html#request_matchers">request matcher</a>.</p>

<button id="button_active_expectations" class="accordion title"><strong>Retrieving Active Expectations Code Examples</strong></button>
<div class="panel title">
    <button id="button_retrieve_all_active_expectations" class="accordion">retrieve all active expectations</button>
    <div class="panel">
        <button class="accordion inner">Java</button>
        <div class="panel">
            <pre class="prettyprint lang-java code"><code class="code">Expectation[] activeExpectations = new MockServerClient("localhost", 1080)
    .retrieveActiveExpectations(
        request()
    );</code></pre>
        </div>
        <button class="accordion inner">JavaScript</button>
        <div class="panel">
            <pre class="prettyprint lang-javascript code"><code class="code">var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
    .retrieveActiveExpectations({})
    .then(
        function (activeExpectations) {
            console.log(JSON.stringify(activeExpectations));
        },
        function (error) {
            console.log(error);
        }
    );</code></pre>
        </div>
        <button class="accordion inner">REST API</button>
        <div class="panel">
            <pre class="prettyprint code"><code class="code">curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=ACTIVE_EXPECTATIONS"</code></pre>
        </div>
    </div>
    <button id="button_retrieve_active_expectations_using_request_matcher" class="accordion">retrieve active expectations using request matcher</button>
    <div class="panel">
        <button class="accordion inner">Java</button>
        <div class="panel">
            <pre class="prettyprint lang-java code"><code class="code">Expectation[] activeExpectations = new MockServerClient("localhost", 1080)
    .retrieveActiveExpectations(
        request()
            .withPath("/some/path")
            .withMethod("POST")
    );</code></pre>
        </div>
        <button class="accordion inner">JavaScript</button>
        <div class="panel">
            <pre class="prettyprint lang-javascript code"><code class="code">var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080).retrieveActiveExpectations({
    "path": "/some/path",
    "method": "POST"
}).then(
    function (activeExpectations) {
        console.log(JSON.stringify(activeExpectations));
    },
    function (error) {
        console.log(error);
    }
);</code></pre>
        </div>
        <button class="accordion inner">REST API</button>
        <div class="panel">
            <pre class="prettyprint code"><code class="code">curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=ACTIVE_EXPECTATIONS" -d '{
    "path": "/some/path",
    "method": "POST"
}'</code></pre>
        </div>
    </div>
    <button id="button_retrieve_active_expectations_as_java" class="accordion">retrieve active expectations as java</button>
    <div class="panel">
        <button class="accordion inner">Java</button>
        <div class="panel">
            <pre class="prettyprint lang-java code"><code class="code">String activeExpectations = new MockServerClient("localhost", 1080)
    .retrieveActiveExpectations(
        request()
            .withPath("/some/path")
            .withMethod("POST"),
        Format.JAVA
    );</code></pre>
        </div>
        <button class="accordion inner">REST API</button>
        <div class="panel">
            <pre class="prettyprint code"><code class="code">curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=ACTIVE_EXPECTATIONS&format=JAVA" -d '{
    "path": "/some/path"
}'</code></pre>
        </div>
    </div>
    <button id="button_retrieve_active_expectations_as_json" class="accordion">retrieve active expectations as json</button>
    <div class="panel">
        <button class="accordion inner">Java</button>
        <div class="panel">
            <pre class="prettyprint lang-java code"><code class="code">String activeExpectations = new MockServerClient("localhost", 1080)
    .retrieveActiveExpectations(
        request()
            .withPath("/some/path")
            .withMethod("POST"),
        Format.JSON
    );</code></pre>
        </div>
        <button class="accordion inner">JavaScript</button>
        <div class="panel">
            <pre class="prettyprint lang-javascript code"><code class="code">var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080).retrieveActiveExpectations({
    "path": "/some/path",
    "method": "POST"
}).then(
    function (activeExpectations) {
        console.log(JSON.stringify(activeExpectations));
    },
    function (error) {
        console.log(error);
    }
);</code></pre>
        </div>
        <button class="accordion inner">REST API</button>
        <div class="panel">
            <pre class="prettyprint code"><code class="code">curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=ACTIVE_EXPECTATIONS&format=JSON" -d '{
    "path": "/some/path"
}'</code></pre>
        </div>
    </div>
</div>

<a name="retrieving_recorded_expectations" class="anchor" href="#retrieving_recorded_expectations">&nbsp;</a>

<h2>Retrieving Recorded Expectations</h2>

<p>For MockServer <a href="/mock_server/getting_started.html#forward_action">forward actions</a> or all proxy requests expectations are recorded containing the request received and response returned.</p>

<p>It is possible to retrieve the recorded expectations, as show below in the code examples.</p>

<p>Expectations are returned in the order they have been recorded, and which expectations are returned can be filter using a <a href="/mock_server/getting_started.html#request_matchers">request matcher</a>.</p>

<button id="button_recorded_expectations" class="accordion title"><strong>Retrieving Recorded Expectations Code Examples</strong></button>
<div class="panel title">
    <button id="button_retrieve_all_recorded_expectations" class="accordion">retrieve all recorded expectations</button>
    <div class="panel">
        <button class="accordion inner">Java</button>
        <div class="panel">
            <pre class="prettyprint lang-java code"><code class="code">Expectation[] recordedExpectations = new MockServerClient("localhost", 1080)
    .retrieveRecordedExpectations(
        request()
    );</code></pre>
        </div>
        <button class="accordion inner">JavaScript</button>
        <div class="panel">
            <pre class="prettyprint lang-javascript code"><code class="code">var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
    .retrieveRecordedExpectations({})
    .then(
        function (recordedExpectations) {
            console.log(JSON.stringify(recordedExpectations));
        },
        function (error) {
            console.log(error);
        }
    );</code></pre>
        </div>
        <button class="accordion inner">REST API</button>
        <div class="panel">
            <pre class="prettyprint code"><code class="code">curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=RECORDED_EXPECTATIONS"</code></pre>
        </div>
    </div>
    <button id="button_retrieve_recorded_expectations_using_request_matcher" class="accordion">retrieve recorded expectations using request matcher</button>
    <div class="panel">
        <button class="accordion inner">Java</button>
        <div class="panel">
            <pre class="prettyprint lang-java code"><code class="code">Expectation[] recordedExpectations = new MockServerClient("localhost", 1080)
    .retrieveRecordedExpectations(
        request()
            .withPath("/some/path")
            .withMethod("POST")
    );</code></pre>
        </div>
        <button class="accordion inner">JavaScript</button>
        <div class="panel">
            <pre class="prettyprint lang-javascript code"><code class="code">var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080).retrieveRecordedExpectations({
    "path": "/some/path",
    "method": "POST"
}).then(
    function (recordedExpectations) {
        console.log(JSON.stringify(recordedExpectations));
    },
    function (error) {
        console.log(error);
    }
);</code></pre>
        </div>
        <button class="accordion inner">REST API</button>
        <div class="panel">
            <pre class="prettyprint code"><code class="code">curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=RECORDED_EXPECTATIONS" -d '{
    "path": "/some/path",
    "method": "POST"
}'</code></pre>
        </div>
    </div>
    <button id="button_retrieve_recorded_expectations_as_java" class="accordion">retrieve recorded expectations as java</button>
    <div class="panel">
        <button class="accordion inner">Java</button>
        <div class="panel">
            <pre class="prettyprint lang-java code"><code class="code">String recordedExpectations = new MockServerClient("localhost", 1080)
    .retrieveRecordedExpectations(
        request()
            .withPath("/some/path")
            .withMethod("POST"),
        Format.JAVA
    );</code></pre>
        </div>
        <button class="accordion inner">REST API</button>
        <div class="panel">
            <pre class="prettyprint code"><code class="code">curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=RECORDED_EXPECTATIONS&format=JAVA" -d '{
    "path": "/some/path"
}'</code></pre>
        </div>
    </div>
    <button id="button_retrieve_recorded_expectations_as_json" class="accordion">retrieve recorded expectations as json</button>
    <div class="panel">
        <button class="accordion inner">Java</button>
        <div class="panel">
            <pre class="prettyprint lang-java code"><code class="code">String recordedExpectations = new MockServerClient("localhost", 1080)
    .retrieveRecordedExpectations(
        request()
            .withPath("/some/path")
            .withMethod("POST"),
        Format.JSON
    );</code></pre>
        </div>
        <button class="accordion inner">JavaScript</button>
        <div class="panel">
            <pre class="prettyprint lang-javascript code"><code class="code">var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080).retrieveRecordedExpectations({
    "path": "/some/path",
    "method": "POST"
}).then(
    function (recordedExpectations) {
        console.log(JSON.stringify(recordedExpectations));
    },
    function (error) {
        console.log(error);
    }
);</code></pre>
        </div>
        <button class="accordion inner">REST API</button>
        <div class="panel">
            <pre class="prettyprint code"><code class="code">curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=RECORDED_EXPECTATIONS&format=JSON" -d '{
    "path": "/some/path"
}'</code></pre>
        </div>
    </div>
</div>

<a name="retrieving_recorded_logs" class="anchor" href="#retrieving_recorded_logs">&nbsp;</a>

<h2>Retrieving Recorded Logs</h2>

<p>MockServer and the proxy record log messages for all major actions, including:</p>
<ul>
    <li>adding expectations</li>
    <li><a href="/mock_server/getting_started.html#request_matchers">matching requests</a></li>
    <li>executing actions (<a href="/mock_server/getting_started.html#response_action">response</a>, <a href="/mock_server/getting_started.html#forward_action">forward</a>, <a href="/mock_server/getting_started.html#callback_action">callback</a> & <a href="/mock_server/getting_started.html#error_action">error</a>)</li>
    <li>returning responses</li>
    <li>clearing logs, expectations & recorded requests</li>
    <li>resetting logs, expectations & recorded requests</li>
</ul>

<p>It is possible to retrieve the recorded log messages, as show below in the code examples.</p>

<p>Log messages are returned in the order they have been recorded, and which log messages are returned can be filter using a <a href="/mock_server/getting_started.html#request_matchers">request matcher</a>.</p>

<button id="button_recorded_log_messages" class="accordion title"><strong>Retrieving Recorded Log Events Code Examples</strong></button>
<div class="panel title">
    <button id="button_retrieve_all_recorded_log_messages" class="accordion">retrieve all recorded log messages</button>
    <div class="panel">
        <button class="accordion inner">Java</button>
        <div class="panel">
            <pre class="prettyprint lang-java code"><code class="code">String logMessages = new MockServerClient("localhost", 1080)
    .retrieveLogMessages(
        request()
    );</code></pre>
        </div>
        <button class="accordion inner">JavaScript</button>
        <div class="panel">
            <pre class="prettyprint lang-javascript code"><code class="code">var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
    .retrieveLogMessages({})
    .then(
        function (logMessages) {
            // logMessages is a String[]
            console.log(logMessages);
        },
        function (error) {
            console.log(error);
        }
    );</code></pre>
        </div>
        <button class="accordion inner">REST API</button>
        <div class="panel">
            <pre class="prettyprint code"><code class="code">curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=LOGS"</code></pre>
        </div>
    </div>
    <button id="button_retrieve_recorded_log_messages_using_request_matcher" class="accordion">retrieve recorded log messages using request matcher</button>
    <div class="panel">
        <button class="accordion inner">Java</button>
        <div class="panel">
            <pre class="prettyprint lang-java code"><code class="code">String logMessages = new MockServerClient("localhost", 1080)
    .retrieveLogMessages(
        request()
            .withPath("/some/path")
            .withMethod("POST")
    );</code></pre>
        </div>
        <button class="accordion inner">JavaScript</button>
        <div class="panel">
            <pre class="prettyprint lang-javascript code"><code class="code">var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
    .retrieveLogMessages({
        "path": "/some/path",
        "method": "POST"
    })
    .then(
        function (logMessages) {
            // logMessages is a String[]
            console.log(logMessages);
        },
        function (error) {
            console.log(error);
        }
    );</code></pre>
        </div>
        <button class="accordion inner">REST API</button>
        <div class="panel">
            <pre class="prettyprint code"><code class="code">curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=LOGS" -d '{
    "path": "/some/path",
    "method": "POST"
}'</code></pre>
        </div>
    </div>
    <button id="button_retrieve_recorded_log_messages_as_array" class="accordion">retrieve recorded log messages as array</button>
    <div class="panel">
        <button class="accordion inner">Java</button>
        <div class="panel">
            <pre class="prettyprint lang-java code"><code class="code">String[] logMessages = new MockServerClient("localhost", 1080)
    .retrieveLogMessagesArray(
        request()
            .withPath("/some/path")
    );</code></pre>
        </div>
        <button class="accordion inner">JavaScript</button>
        <div class="panel">
            <pre class="prettyprint lang-javascript code"><code class="code">var mockServerClient = require('mockserver-client').mockServerClient;
mockServerClient("localhost", 1080)
    .retrieveLogMessages({
        "path": "/some/path"
    })
    .then(
        function (logMessages) {
            // logMessages is a String[]
            console.log(logMessages);
        },
        function (error) {
            console.log(error);
        }
    );</code></pre>
        </div>
    </div>
</div>

<a name="logging-levels" class="anchor" href="#logging-levels">&nbsp;</a>

<h2>Logging</h2>

<p>All interactions with the MockServer are logged including setting up expectations, matching expectations, clearing expectations and verifying requests. The log can be particularly helpful when trying to debug why a test is failing or expectations are not being matched.</p>

<p>The following information is logged:</p>

<ul>
    <li><strong>WARN</strong> - exceptions, errors</li>
    <li><strong>INFO</strong> - all interactions with the MockServer including setting up expectations, matching expectations, clearing expectations and verifying requests</li>
    <li><strong>TRACE</strong> - all matcher results, including when specific matchers fail (such as HeaderMatcher)</li>
</ul>

<p>The <strong>TRACE</strong> level logging results in a lot of verbose logging but can be very helpful to debug why a complex matcher (such as the JSON Schema matcher) is not matching.</p>

<p>When MockServer is run from the command line, Maven plugin, npm module or Grunt plugin the log is written to a file called <strong>mockserver.log</strong> in the current working directory where the MockServer is running.</p>

<a name="logging_with_api" class="anchor" href="#logging_with_api">&nbsp;</a>

<h3>Logging with JUnit @Rule or API</h3>

<p>If the MockSever is being launched using the <a href="/mock_server/running_mock_server.html#junit_rule"><strong>JUnit @Rule</strong></a> or <a href="/mock_server/running_mock_server.html#client_api"><strong>programmatically via an API</strong></a> then a custom
	<a href="http://logback.qos.ch">logback</a> configuration file to override the default MockServer or MockServer Proxy logging settings. An example
	<a href="https://github.com/jamesdbloom/mockserver/blob/master/mockserver-netty/src/main/resources/example_logback.xml">logback configuration file</a> is available in github.</p>

<p>A custom <a href="http://logback.qos.ch">logback</a> configuration file can be specified using the <span class="inline_code">logback.configurationFile</span> system property with an absolute or relative file path or a classpath, as follows: <code class="code inline">-Dlogback.configurationFile=example_logback.xml</code></p>

<a name="logging_with_command_line" class="anchor" href="#logging_with_command_line">&nbsp;</a>

<h3>Logging with Command Line</h3>

<p>When running MockServer directly from <a href="/mock_server/running_mock_server.html#running_from_command_line">the command line</a> the command line argument <span class="inline_code">-logLevel</span> can be used to set the log level, as follows:</p>

<pre><code class="code">java -jar ~/Downloads/mockserver-netty-5.6.1-jar-with-dependencies.jar -serverPort <span class="numeric_literal">1080</span> -logLevel DEBUG</code></pre>

<p>Alternatively a system property <span class="inline_code">mockserver.logLevel</span> can be used to set the log level, as follows:</p>

<pre><code class="code">java -Dmockserver.logLevel=INFO -jar ~/Downloads/mockserver-netty-5.6.1-jar-with-dependencies.jar -serverPort <span class="numeric_literal">1080</span></code></pre>

<p>It is also possible to specify a custom <a href="http://logback.qos.ch">logback</a> configuration file to override the default MockServer or MockServer Proxy logging settings. An example <a href="https://github.com/jamesdbloom/mockserver/blob/master/mockserver-netty/src/main/resources/example_logback.xml">logback configuration file</a> is available in github.</p>

<p>A custom <a href="http://logback.qos.ch">logback</a> configuration file can be specified using the <span class="inline_code">logback.configurationFile</span> system property with an absolute or relative file path or a classpath, as follows:</p>

<pre><code class="code">java -Droot.logLevel=WARN -Dmockserver.logLevel=INFO -Dlogback.configurationFile=example_logback.xml -jar ~/Downloads/mockserver-netty-5.6.1-jar-with-dependencies.jar -serverPort <span class="numeric_literal">1080</span></code></pre>

<p>A custom <a href="http://logback.qos.ch">logback</a> configuration file will also be automatically picked up if it is called <strong>logback.xml</strong> and is in the root of the classpath, however, the jar-with-dependencies already contains a <strong>logback.xml</strong> file, so to override this, the overriding <strong>logback.xml</strong> file must be higher (i.e. earlier) in the classpath.</p>

<a name="logging_with_maven_plugin" class="anchor" href="#logging_with_maven_plugin">&nbsp;</a>

<h3>Logging with Maven Plugin</h3>

<p>The mockserver-maven-plugin provides a logLevel settings that can be used to define the log level for all MockServer classes, as follows:</p>

<pre><code class="code xml"> &lt;<span class="element">plugin</span>&gt;
     &lt;<span class="element">groupId</span>&gt;<span class="element_value">org.mock-server</span>&lt;/<span class="element">groupId</span>&gt;
     &lt;<span class="element">artifactId</span>&gt;<span class="element_value">mockserver-maven-plugin</span>&lt;/<span class="element">artifactId</span>&gt;
     &lt;<span class="element">version</span>&gt;<span class="element_value">5.6.1</span>&lt;/<span class="element">version</span>&gt;
     &lt;<span class="element">configuration</span>&gt;
        &lt;<span class="element">serverPort</span>&gt;<span class="element_value">1080</span>&lt;/<span class="element">serverPort</span>&gt;
        &lt;<span class="element">logLevel</span>&gt;<span class="element_value">DEBUG</span>&lt;/<span class="element">logLevel</span>&gt;
     &lt;/<span class="element">configuration</span>&gt;
     &lt;<span class="element">executions</span>&gt;
         &lt;<span class="element">execution</span>&gt;
             &lt;<span class="element">id</span>&gt;<span class="element_value">process-test-classes</span>&lt;/<span class="element">id</span>&gt;
             &lt;<span class="element">phase</span>&gt;<span class="element_value">process-test-classes</span>&lt;/<span class="element">phase</span>&gt;
             &lt;<span class="element">goals</span>&gt;
                 &lt;<span class="element">goal</span>&gt;<span class="element_value">runForked</span>&lt;/<span class="element">goal</span>&gt;
             &lt;/<span class="element">goals</span>&gt;
         &lt;/<span class="element">execution</span>&gt;
         &lt;<span class="element">execution</span>&gt;
             &lt;<span class="element">id</span>&gt;<span class="element_value">verify</span>&lt;/<span class="element">id</span>&gt;
             &lt;<span class="element">phase</span>&gt;<span class="element_value">verify</span>&lt;/<span class="element">phase</span>&gt;
             &lt;<span class="element">goals</span>&gt;
                 &lt;<span class="element">goal</span>&gt;<span class="element_value">stopForked</span>&lt;/<span class="element">goal</span>&gt;
             &lt;/<span class="element">goals</span>&gt;
         &lt;/<span class="element">execution</span>&gt;
     &lt;/<span class="element">executions</span>&gt;
 &lt;/<span class="element">plugin</span>&gt;</code></pre>

<a name="logging-with-node" class="anchor" href="#logging-with-node">&nbsp;</a>

<h3>Logging with npm module</h3>

<p>When running MockServer using the <a href="/mock_server/running_mock_server.html#mockserver_node"><strong>mockserver-node</strong></a> Grunt plugin and Node.js (npm) module the <span class="inline_code">verbose</span> option can be used to enable <strong>INFO</strong> level logging and the <span class="inline_code">trace</span> option can be used to enable <strong>TRACE</strong> level logging.</p>

<p>It is generally recommended to enable <span class="inline_code">verbose</span> which should provide the correct amount of information, <span class="inline_code">trace</span> is only required for very low level debugging.</p>

<pre class="prettyprint lang-java code"><code class="code">var mockserver = require('mockserver-node');

mockserver
    .start_mockserver({
        serverPort: 1080,
        verbose: true,
        trace: true
    })
    .then(
        function () {
            console.log("started MockServer");
        },
        function (error) {
            console.log(JSON.stringify(error));
        }
    );</code></pre>

<h3>Logging with Grunt plugin</h3>

<p>When running MockServer using the <a href="/mock_server/running_mock_server.html#mockserver_node"><strong>mockserver-node</strong></a> as a Grunt plugin module the <span class="inline_code">verbose</span> option can be used to enable <strong>INFO</strong> level logging and the <span class="inline_code">trace</span> option can be used to enable <strong>TRACE</strong> level logging.  The <span class="inline_code">--verbose</span> command line flag can also be used to enable the <strong>mockserver-node</strong> verbose option from the command line.</p>

<p>It is generally recommended to enable <span class="inline_code">verbose</span> which should provide the correct amount of information, <span class="inline_code">trace</span> is only required for very low level debugging.</p>

<pre class="prettyprint lang-java code"><code class="code">grunt.initConfig({
        start_mockserver: {
            options: {
                serverPort: 1080,
                verbose: true,
                trace: true
            }
        },
        stop_mockserver: {
            options: {
                serverPort: 1080
            }
        }
});

grunt.loadNpmTasks('mockserver-node');</code></pre>

<a name="disabling-logging" class="anchor" href="#disabling-logging">&nbsp;</a>

<h3>Disabling Logging</h3>

<p>To disable logging the following options can be used:</p>

<ul>
<li><code class="code inline">-Dmockserver.logLevel=OFF</code> - to disable logging from the MockServer and Proxy classes</li>
<li><code class="code inline">-Droot.logLevel=OFF</code> - to disable all logging from all other classes</li>
</ul>

<p>If logging is disabled then no log file will be created.  This is because the log files are only created when the first item is written to the log file.</p>
